# value是必须有的，是赋值符左边的变量
`task2<-` <- function(x, y, value) {
    x <- y + value
    x
}


x <- 1
task2(x, 332) <- 4
x


`%diff%` <- function(x, y) {
    z <- setdiff(x, y)
    return(z)
}


1 %>% .() + 1
1 %>% `+`(., 2)


a <- vector('list',length = 12)

for(i in 1:12){
	a[i] <- i
}




f <- function(FUN, ...) {
    l <- list(...)
    l <- do.call(FUN, args = l)
    return(l)
}

f("max", 0, 1, 2, 3, 4, 1)
f("min", 0, 1, 2, 3, 4, 1)
f("sum", 0, 1, 2, 3, 4, 1)
f("ave", 0, 1, 2, 3, 4, 1)


call_obj <- call("f", "sum", 1, 54)
eval(call_obj)

suppressMessages(library(tidyverse)); suppressMessages(library(magrittr))

mtcars

theme_bw2 <- function(base_size = 11, ...) {
    l <- list(...)
    do.call("theme_bw", list(c("base_size" = base_size), l)) %+replace% theme(text = element_text(color = "black"))
}


c('x' = 12,l)

ggplot(mtcars, aes(x = vs, y = disp)) +
    geom_point()+
    theme_bw2(4)


f <- \(a = 1, b = 2, c = 3){
    print(a + b + c)
}

call_boj <- call('f',c = 11)

eval(call_boj)


library(Seurat)

rownames()

showMethods("rownames<-")


`rownames<-` <- function(...){
    UseMethod('rownames<-')
}

`rownames<-.foo` <-
    function(obj, value) {
        x <- obj$x
        if (is.data.frame(x)) {
            row.names(x) <- value
        } else {
            dn <- dimnames(x)
            if (is.null(dn)) {
                if (is.null(value)) {
                    return(x)
                }
                if ((nd <- length(dim(x))) < 1L) {
                    stop("attempt to set 'rownames' on an object with no dimensions")
                }
                dn <- vector("list", nd)
            }
            if (length(dn) < 1L) {
                stop("attempt to set 'rownames' on an object with no dimensions")
            }
            if (is.null(value)) {
                dn[1L] <- list(NULL)
            } else {
                dn[[1L]] <- value
            }
            dimnames(x) <- dn
        }
        obj$x <- x
        return(obj)
    }

aa = list(x = data.frame(a = 1:3,b = letters[1:3]),y = 12,z = tibble())

class(aa) <- "foo"

typeof(aa)

rownames(aa) <- c('asd','asdd2','asd3')
do.call('rownames<-',list(aa,c('asd1','asdd2','asd3')))


formalArgs()